package cn.hs.ph.serviet;

import cn.hs.ph.dao.impl.courierStationDaoimpl;
import cn.hs.ph.entity.courierStation;
import cn.hs.ph.util.Result;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/courierStation")
public class courierStationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        courierStationDaoimpl courierStationDao = new courierStationDaoimpl();
        String action = req.getParameter("action");
        if (action.equals("query")) {
            Map<String,String> map=new HashMap<>();
            String pageNum = req.getParameter("pageNum");
            String pageSize = req.getParameter("pageSize");
            String courierStationName = req.getParameter("courierStationName");
            String communityName = req.getParameter("communityName");
            String courierStationStatus = req.getParameter("courierStationStatus");
            String startTime = req.getParameter("startTime");
            String endTime = req.getParameter("endTime");
            map.put("pageNum", pageNum);
            map.put("pageSize", pageSize);
            map.put("courierStationName", courierStationName);
            map.put("communityName", communityName);
            map.put("courierStationStatus", courierStationStatus);
            map.put("startTime", startTime);
            map.put("endTime", endTime);
            List<courierStation> list=null;
            int total=0;

            try {
                list = courierStationDao.selectAll(map);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }


            try {
                 total = courierStationDao.selectCount(map);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            HashMap map1=new HashMap();
            map1.put("total", total);
            map1.put("list", list);
            Result success = Result.success(map1);
            resp.getWriter().write(JSON.toJSONString(success));


        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
